import os
from configparser import ConfigParser

from utils.lzsd_utils import LZSDUtils

_config_ini_filepath = LZSDUtils.get_app_dir_file_path("config.ini")



if not os.path.exists(_config_ini_filepath):
    with open(_config_ini_filepath, 'w') as f:
        f.close()

def config_get_value(section, key, default=""):
    config = ConfigParser()
    config.read(_config_ini_filepath)
    v = config.get(section, key)
    if not v:
        v = default
    return v

def config_set_value(section, key, value):
    config = ConfigParser()
    config.read(_config_ini_filepath)
    config.set(section, key, value)
    with open(_config_ini_filepath, 'w') as configfile:
        config.write(configfile)
        configfile.close()

def config_get_data_path():
    datas = config_get_value("data", "save", LZSDUtils.get_app_dir_file_path("data") + os.sep)
    return config_get_value("data", "save", LZSDUtils.get_app_dir_file_path("data") + os.sep)

_data_path = config_get_data_path()
if not os.path.exists(_data_path):
    os.makedirs(_data_path)
    config_set_value("data", "save", _data_path)